<template>
    <div class="mallWallet">
        <van-nav-bar title="商城钱包" left-arrow @click-left="onClickLeft" />
        <div class="card">
            <span>钱包金额</span>
            <span>￥{{ userInfo.hasshop }}</span>
            <span>金额(元)</span>
        </div>
        <div class="title">流水明细</div>
        <div class="list">

            <van-empty description="暂无数据" style="height: 100%;" v-if="flowingList.length == 0" />
            <div class="listItem" v-for="item in flowingList" :key="item.id">
                <div class="left">
                    <span>{{ item.change_type }}</span>
                    <span><span>{{ item.record_type == 0 ? '消费了' : '返回了' }}</span>{{ item.money }}</span>
                </div>
                <div class="right">
                    <span><span>{{ item.record_type == 0 ? '-' : '+' }}</span>{{ item.money }}</span>
                    <span>{{ item.createtime }}</span>
                </div>
            </div>
        </div>
    </div>
</template>

<script lang="ts" setup>
import { ref, onMounted } from 'vue';
import { Toast } from 'vant';
import { flowing } from '../../../api/index';
const userInfo = JSON.parse(window.localStorage.getItem("userInfo") as string)
// 定义onClickLeft方法
const onClickLeft = () => history.back();

//  累计充值积分
const page_size = ref('')
const moneytype = ref('')
const flowingList = ref<any>([])
const total = ref(0)
const getflowList = () => {
    let formData = new FormData();
    formData.append("type", (page_size.value, moneytype.value))
    flowing(formData).then((res: any) => {
        // console.log(res.data.list.total);
        if (res.code == 1) {
            flowingList.value = res.data.list.data;
            total.value = res.data.list.total
        } else {
            Toast(res.msg);
        }
    });
};

// 如果需要在组件挂载后执行某些操作，可以使用onMounted
onMounted(() => {
    // 组件挂载后的逻辑
    // console.log(useRouter())
    getflowList()
});


</script>

<style scoped lang="less">
@import url(../../../style/common.css);

.mallWallet {
    background: #F6F7F9;
    width: 100%;
    height: calc(100vh - 10px);

    .van-nav-bar {
        height: 52px;
    }

    .card {
        width: 345px;
        height: 158px;
        background-image: url('../../../assets/my/shopping.png');
        background-size: 100% 158px;
        background-repeat: no-repeat;
        display: flex;
        justify-content: space-around;
        align-items: flex-start;
        flex-direction: column;
        padding: 24px 26px;
        box-sizing: border-box;
        margin: 28px 15px;

        span {
            font-size: 12px;
            color: #FFFFFF;
            font-weight: 400;

            &:nth-child(1) {
                font-size: 16px;
            }

            &:nth-child(2) {
                font-size: 20px;
            }
        }

    }

    .title {
        font-size: 16px;
        color: #3D3D3D;
        text-align: left;
        margin-left: 15px;
    }

    .list {
        .listItem {
            margin: 16px 15px 0;
            height: 80px;
            background: #FFFFFF;
            border-radius: 13px 13px 13px 13px;
            display: flex;
            justify-content: space-between;
            padding: 18px 16px;
            box-sizing: border-box;

            .left,
            .right {
                display: flex;
                justify-content: space-between;
                flex-direction: column;
                text-align: left;

                span {
                    &:nth-child(1) {
                        font-size: 16px;
                        color: #232323;
                    }

                    &:nth-child(2) {
                        font-size: 13px;
                        color: #999999;
                    }
                }
            }

            .right {
                text-align: right;
            }
        }
    }
}

:deep(.van-nav-bar__left .van-badge__wrapper) {
    color: #272635;
}
</style>